package com.warm.androidstudy.view.room.model;

import androidx.room.ColumnInfo;
import androidx.room.Embedded;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;

/**
 * 使用方法
 * 1.数据表的实体类。如果不想使用Person为类名可以这么写@Entity(tableName = "gsm") 自定义
 * 2.复合主键：@Entity(primaryKeys = {"uid","name"}) //name字段要用@NonNull标注
 * 3.单列索引 @Entity(indices = {@Index(value = "name")})
 * 4.单列索引惟一性 @Entity(indices = {@Index(value = "name", unique = true)})
 * 5.组合索引 @Entity(indices ={@Index(value = {"name","age"})})
 * 6.组合索引惟一性 @Entity(indices ={@Index(value = {"name","age"},unique = true)})
 * 7.混用索引 @Entity(indices ={@Index(value = "name"),@Index(value = {"name","age"},unique = true)})
 */
@Entity

public class Person {
    @PrimaryKey() //每个实体类都须要一个惟一的标识
    @ColumnInfo(name = "uid")// 数据表中字段名称。
    private int uid;
    private String name;
    private int age;
    @Ignore//标注不须要添加到数据表中的属性。
    private int money;
//    @Embedded// 实体类中引用其余实体类
//    private Address address;
    //@Embedded(prefix = "one"),这个是区分惟一性的，好比说一这我的可能有2个地址相似于tag，那么在数据表中就会以prefix+属性值命名
    @Embedded(prefix = "one")
    private Address address;
//    @Embedded(prefix = "two")
//    private Address address;


    public int getUid() {
        return uid;
    }

    public void setUid(int uid) {
        this.uid = uid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }
}
